package tms.view;

import javax.swing.DefaultComboBoxModel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.FormSpecs;
import com.jgoodies.forms.layout.RowSpec;

public class ExtraInfoPanel extends JPanel {

    private static final long serialVersionUID = 1L;

    private JPasswordField txtEnterAPassword;
    private JPasswordField txtConfirmAPassword;
    private JTextField txtPassportNumber;
    private JComboBox cmbIssuingCountry;

    public ExtraInfoPanel() {
        setLayout(new FormLayout(new ColumnSpec[] {
                ColumnSpec.decode("74dlu"),
                FormSpecs.RELATED_GAP_COLSPEC,
                ColumnSpec.decode("74dlu"),
                ColumnSpec.decode("50dlu"),
                ColumnSpec.decode("74dlu"),
                FormSpecs.RELATED_GAP_COLSPEC,
                ColumnSpec.decode("74dlu"),
                FormSpecs.GROWING_BUTTON_COLSPEC},
            new RowSpec[] {
                FormSpecs.UNRELATED_GAP_ROWSPEC,
                RowSpec.decode("23px"),
                FormSpecs.UNRELATED_GAP_ROWSPEC,
                RowSpec.decode("23px")}));
        add(Tools.createLabel("Enter a password: "), "1, 2, left, fill");
        txtEnterAPassword = Tools.createPasswordField();
        add(txtEnterAPassword, "3, 2, fill, fill");
        add(Tools.createLabel("Confirm password: "), "5, 2, left, fill");
        txtConfirmAPassword = Tools.createPasswordField();
        add(txtConfirmAPassword, "7, 2, fill, fill");
        add(Tools.createLabel("Passport number: "), "1, 4, left, fill");
        txtPassportNumber = Tools.createTextField("");
        add(txtPassportNumber, "3, 4, fill, fill");
        add(Tools.createLabel("Issuing country: "), "5, 4, left, fill");
        cmbIssuingCountry = Tools.createComboBox();
        cmbIssuingCountry.setModel(new DefaultComboBoxModel(new String[] {"Vietnam", "USA", "France"}));
        add(cmbIssuingCountry, "7, 4, fill, fill");
    }

    public boolean checkValidPassword() {
        String password = String.copyValueOf(txtEnterAPassword.getPassword());
        String confirm = String.copyValueOf(txtConfirmAPassword.getPassword());

        return password.compareToIgnoreCase(confirm) == 0;
    }

    public String getPassword() {
        return String.copyValueOf(txtEnterAPassword.getPassword());
    }

    public String getConfirmPassword() {
        return String.copyValueOf(txtConfirmAPassword.getPassword());
    }

    public String getPassportNumber() {
        return txtPassportNumber.getText();
    }

    public void setPassportNumber(String txtPassportNumber) {
        this.txtPassportNumber.setText(txtPassportNumber);
    }

    public String getIssuingCountry() {
        return (String) cmbIssuingCountry.getSelectedItem();
    }

    public void setIssuingCountry(String s) {
        for (int i = 0; i < cmbIssuingCountry.getItemCount(); i++) {
            if (((String) cmbIssuingCountry.getItemAt(i)).compareToIgnoreCase(s) == 0) {
                cmbIssuingCountry.setSelectedIndex(i);
                break;
            }
        }
    }
}
